package com.shishuo.cms.service;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.apache.ibatis.annotations.Param;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.shishuo.cms.dao.IBaseDAO;
import com.shishuo.cms.exception.BusinessException;
public abstract class BaseService <T,ID extends Serializable>{
	protected final Logger logger = Logger.getLogger(this.getClass());
	@Resource
	protected IBaseDAO<T, ID> baseDao;

	public void setBaseDao(IBaseDAO<T, ID> baseDao) {
		this.baseDao = baseDao;
	}

	public int insert(T entity) throws Exception{
		return baseDao.add(entity);
    }
  
    public int update(T entity) throws Exception{
        return baseDao.update(entity);
    }
    
    
    /**
     * 获取指定的唯一标识符对应的持久化对象
     *
     * @param id 指定的唯一标识符
     * @return 指定的唯一标识符对应的持久化对象，如果没有对应的持久化对象，则返回null。
     */
	public T getById(ID id) throws Exception{
		return baseDao.getById(id);
	}
	
	/**
	 * 删除
	 * 
	 * @param adminId
	 * @return Integer
	 * 
	 */
	public int deleteById(ID id) throws Exception{
		//throw new BusinessException("500","xxx");
		return baseDao.deleteById(id);
	}
	
	
	/**
	 * 获取所有
	 * 
	 * @param offset
	 * @param rows
	 * @return List<Admin>
	 * 
	 */
	public List<T> getAllList(long offset,long rows) throws Exception{
		return baseDao.getAllList(offset, rows);
	}
	
	public List<T> getAllList() throws Exception{
		return baseDao.getAllList();
	}
	
	/**
	 * 获取所有数量
	 * 
	 * @return Integer
	 * 
	 */
	public int getAllListCount() throws Exception{
		return baseDao.getAllListCount();
	}
    
    
    
}
